
#include "DeciplineCompositor.h"

size_t const DeciplineCompositor::default_capacity = 4;

DeciplineCompositor::DeciplineCompositor(void)
:count(0), capacity(default_capacity), compositor(new Decipline*[capacity])
{
}

DeciplineCompositor::~DeciplineCompositor(void)
{
	for (size_t i = 0; i != count; ++i)
		delete compositor[i];
}

void DeciplineCompositor::addDecipline(Decipline *_pd)
{
	if (count >= capacity)
	{
		Decipline** buffer = new Decipline*[capacity + default_capacity];
		for (size_t i = 0; i!=count; ++i)
		{
			buffer[i] = compositor[i];
		}
		delete compositor;
		compositor = buffer;

	}
	compositor[count] = _pd;
	++count;
}

int DeciplineCompositor::useDeciplines( Matrix<int> const& data ) const
{
	int result(0);
	for (size_t i = 0; i!=count; ++i)
	{
		result += compositor[i]->useDecipline(data);
	}
	return result;
}